<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组的累加</title>
</head>
<body>
    
    <script>
        

        var arr = [10,11,12,13,14];
        const ary = ["10","11","12"];
        const reducer = (accumulator,currentVal) => accumulator + currentVal;
        console.log(arr.reduce(reducer));
        const newArr = ary.map(item => parseInt(item));
        console.log(`ary -- ${newArr.reduce(reducer)}`);

        function accumulator (a) {
            var sum = 0;
            a.forEach(element => {
                sum += parseInt(element);
            });
            return sum;

        }
        console.log(`accumulator -- ${accumulator (ary)}`);

        var stringAry = ["hello1","name3","Jerry5","2my","i4s"];

        function stringArySort () {
            var numberAry = stringAry.map(ele => ele.replace(/[^0-9]/gi,""));
            return numberAry;
        } 

        console.log(stringArySort());

        const c = ["wangshuo","wangzirui"];

        for (var key in c) {
            console.log(`c -- ${key}`);  
        }

        // 二维数组变成一维数组
        var twoArr = [[1,2],[3,4],[5,6]];
        console.log(twoArr.reduce((a,b)=>a.concat(b)));




    </script>
</body>
</html>